<template>
  <el-table
    :data="traderInfo"
    style="width: 100%">
    <el-table-column type="expand">
      <template slot-scope="props">
        <el-form label-position="left" inline class="demo-table-expand">
          <el-form-item label="商家名称">
            <span>{{ props.row.traderName }}</span>
          </el-form-item>
          <el-form-item label="商家车辆">
            <span>{{ props.row.traderCar }}</span>
          </el-form-item>
          <el-form-item label="联系人">
            <span>{{ props.row.traderPerson }}</span>
          </el-form-item>
          <el-form-item label="联系电话">
            <span>{{ props.row.traderTelphone }}</span>
          </el-form-item>
          <el-form-item label="微信号">
            <span>{{ props.row.wechat }}</span>
          </el-form-item>
          <el-form-item label="店铺地址">
            <span>{{ props.row.city }}</span>
          </el-form-item>
          <el-form-item label="备注">
            <span>{{ props.row.desc }}</span>
          </el-form-item>
        </el-form>
      </template>
    </el-table-column>
    <el-table-column
      label="申请 ID"
      prop="_id">
    </el-table-column>
    <el-table-column
      label="商家名称"
      prop="traderName">
    </el-table-column>
    <el-table-column
      label="联系电话"
      prop="traderTelphone">
    </el-table-column>
    <el-table-column label="">
      <template slot-scope="scope">
        <el-button
          size="mini"
          type="success"
          @click="handleEdit(scope.row)">通过</el-button>
        <el-button
          size="mini"
          type="danger"
          @click="handleDelete(scope.row)">拒绝</el-button>
      </template>
    </el-table-column>
  </el-table>
</template>

<script>
import axios from 'axios';
  export default {
    data() {
      return {
        traderInfo:[],
      }
    },
    methods:{
      
      handleEdit(value){
        this.traderInfo._id = value._id
        this.traderInfo.status = 1
        axios.post("http://127.0.0.1:3000/traderStatus",{
          _id:this.traderInfo._id,
          status:this.traderInfo.status
        })
        .then(
              () => {
                this.success();
                this.passTrader()
              },
              () => {
                this.register_failing();
              }
            );
      },
      handleDelete(value){
        this.traderInfo._id = value._id
        this.traderInfo.status = 2
        axios.post("http://127.0.0.1:3000/traderStatus",{
          _id:this.traderInfo._id,
          status:this.traderInfo.status
        })
        .then(
              () => {
                this.reject();
                this.passTrader()
              },
              () => {
                this.register_failing();
              }
            );
      },
      
      // 审核成功判断
      success() {
        this.$message({
          showClose: true,
          message: "审核通过！",
          type: "success",
        });
      },
      // 审核拒绝判断
      reject() {
        this.$message({
          showClose: true,
          message: "拒绝入驻！",
          type: "error",
        });
      },
      passTrader(){
        axios.post("http://127.0.0.1:3000/traderInfo").then((res) => {
          this.traderInfo = res.data;
          console.log(this.traderInfo);
        });
      }
      
    },
    created(){
      this.passTrader()
    }
  }
</script>

<style>
  .demo-table-expand {
    font-size: 0;
  }
  .demo-table-expand label {
    width: 90px;
    color: #99a9bf;
  }
  .demo-table-expand .el-form-item {
    margin-right: 0;
    margin-bottom: 0;
    width: 50%;
  }
</style>